package com.github.bobjoy.java.jdk8;

import org.junit.Test;

import java.util.Optional;

public class OptionalDemo {

    @Test
    public void test() {
        String ss = null;

        Optional<String> os = Optional.of(ss);
        System.out.println( "Full Name is set? " + os.isPresent() );
        System.out.println( "Full Name: " + os.orElse("[none]") );
        System.out.println( os.map( s -> "Hey " + s + "!" ).orElse( "Hey Stranger!" ) );

        System.out.println("======================================");

        Optional< String > firstName = Optional.of( "Tom" );
        System.out.println( "First Name is set? " + firstName.isPresent() );
        System.out.println( "First Name: " + firstName.orElse("[none]") );
        System.out.println( firstName.map( s -> "Hey " + s + "!" ).orElse( "Hey Stranger!" ) );
        System.out.println();
    }

}
